const { mongoose } = require("../util/mongoose");

let solveSchema = mongoose.Schema({
    event: String,
    Remarks: String,//备注
    cTime: String,
    solveTime:String,
    solveState: String,
    admin:String
})
let User = mongoose.model("Solves", solveSchema);
//添加事务
const add = (query = {}) => {
    let collection = new User(query);
    return collection.save()
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}

//修改
const update = (query, updated) => {
    return User.updateOne(query, updated)
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false
        })
}

//删除
const del = (query) => {
    return User.deleteOne(query)
        .then(res => res)
        .catch(err => {
            console.log(err)
            return false
        })
}

//查找 查看总数量
const find = (query={}) => {
    return User.find(query).sort({ cTime: -1 })
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}

//查找 分页
const findpage = (query={},counts ={ skip: 0, limit: 5}) => {
    return User.find(query).sort({ cTime: -1 }).skip(counts.skip).limit(counts.limit)
        .then(res => res)
        .catch(err => { 
            console.log(err);
            return false;
        })
}
module.exports = {
    add, update, del, find, findpage
}